(function ($) {
    $.fn.StoreInitMenu = function (options) {
        var opts = $.extend({}, $.fn.StoreInitMenu.defaults, options);
        var base = this;
        var thisTitle = $('#shopNavigation');
        var Z_SubList = $('#shopNavigationItem').find('.popup-content');
        var navPosTop = $(base).offset().top;
        var timeOut = null;

        $(thisTitle).find('.popup-trigger').hover(function (e) {
            clearTimeout(timeOut);
            var thisLi = this;
            if ($(Z_SubList).css("visibility") == "visible") return;
            showSubList(thisLi);
            e.stopPropagation();
        }, function (e) {
            var thisLi = this;
            timeOut = setTimeout(function () {
                hideSubList(thisLi);
            }, 100);

            $(Z_SubList).hover(function (e) {
                clearTimeout(timeOut);
            }, function () {
                timeOut = setTimeout(function () {
                    hideSubList(thisLi);
                }, 100);
            });
            e.stopPropagation();
        });

        var hidenOthers = function (CurntItem) {

        }

        $(Z_SubList).find('.J_TAllCatsTree > .fst-cat').hover(function (e) {
            clearTimeout(timeOut);
            var thisLi = $(this).find('.snd-pop');
            showSub2List($(this).offset.top, thisLi);
            e.stopPropagation();
        }, function (e) {
            var thisLi = $(this).find('.snd-pop');
            timeOut = setTimeout(function () {
                hideSubList(thisLi);
            }, 100);
            hideSub2List(thisLi);
            e.stopPropagation();
        });


        var showSubList = function (thisli) {
            var top = $(thisli).offset().top + $(thisli).height(); -opts.slideHeight;
            //$(thisli).addClass('curr').find('s').addClass('curr');
            //$(thisli).css("visibility", "visible");
            $(Z_SubList).css({ top: top, opacity: 1 }).css("visibility", "visible").stop().animate({ top: top, opacity: 1 });
        };

        var showSub2List = function (top,thisli) {
            //$(thisli).addClass('curr').find('s').addClass('curr');
            //$(thisli).css("visibility", "visible");
            $(thisli).css({ top: top, opacity: 1 }).css("visibility", "visible").stop().animate({ top: top, opacity: 1 });
        };

        var hideSubList = function (thisli) {
            // $(thisli).removeClass('curr').find('s').removeClass('curr');
            $(Z_SubList).css("visibility", "hidden");
        };

        var hideSub2List = function (thisli) {
            // $(thisli).removeClass('curr').find('s').removeClass('curr');
            $(thisli).css("visibility", "hidden");
        };
        //        $(window).resize(function () {
        //            var sTop = $(window).scrollTop();

        //            if (sTop >= navPosTop) {
        //                if ($.browser.msie && $.browser.version < 7) {
        //                    $(base).css({ position: 'absolute', top: sTop });
        //                } else {
        //                    $(base).css({ position: 'fixed', top: 0 });
        //                }
        //            } else {
        //                $(base).css({ position: 'relative', top: 0 });
        //            }
        //        });

        //        $(window).scroll(function () {
        //            var sTop = $(window).scrollTop();

        //            if (sTop >= navPosTop) {
        //                if ($.browser.msie && $.browser.version < 7) {
        //                    $(base).css({ position: 'absolute', top: sTop });
        //                } else {
        //                    $(base).css({ position: 'fixed', top: 0 });
        //                }
        //            } else {
        //                $(base).css({ position: 'relative', top: 0 });
        //            }
        //        });
    };

    $.fn.StoreInitMenu.defaults = {
        slideHeight: 4
    };
})(jQuery);